
using Microsoft.Extensions.DependencyInjection;
using UniversalAdmin.Application.Services;
using Microsoft.Extensions.Configuration;
using UniversalAdmin.Application.Services.Implementations;
using UniversalAdmin.Application.Services.Interfaces;
using UniversalAdmin.Application.Services.Handlers;

namespace UniversalAdmin.Application;

public static class ServiceCollectionExtension
{
    public static IServiceCollection AddApplication(this IServiceCollection services, IConfiguration configuration)
    {
        // 注册应用层服务
        services.AddScoped<IRoleService, RoleService>();
        services.AddScoped<IMenuService, MenuService>();
        services.AddScoped(typeof(IAuthService), typeof(AuthService));
        services.AddScoped<IUserService, UserService>();
        services.AddScoped<IArticleService, ArticleService>();
        services.AddScoped<IArticleCategoryService, ArticleCategoryService>();
        services.AddScoped<ILogService, LogService>();
        services.AddScoped<IFileService, FileService>();
        // 只注册一次MediatR，避免重复触发
        services.AddMediatR(cfg =>
            cfg.RegisterServicesFromAssemblyContaining<UserCreatedEventHandler>());
        return services;
    }
}
